package c.e.a.b.g;

import b.i.b.f;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Executor;
import javax.annotation.concurrent.GuardedBy;

public final class a0<TResult> extends g<TResult> {
    public final Object a = new Object();
    public final y<TResult> b = new y();
    @GuardedBy("mLock")
    public boolean c;
    public volatile boolean d;
    @GuardedBy("mLock")
    public TResult e;
    @GuardedBy("mLock")
    public Exception f;

    public final g<TResult> a(Executor executor, b bVar) {
        this.b.b(new p(executor, bVar));
        p();
        return this;
    }

    public final g<TResult> b(Executor executor, c cVar) {
        this.b.b(new r(executor, cVar));
        p();
        return this;
    }

    public final g<TResult> c(Executor executor, d<? super TResult> dVar) {
        this.b.b(new t(executor, dVar));
        p();
        return this;
    }

    public final <TContinuationResult> g<TContinuationResult> d(a<TResult, TContinuationResult> aVar) {
        return e(i.a, aVar);
    }

    public final <TContinuationResult> g<TContinuationResult> e(Executor executor, a<TResult, TContinuationResult> aVar) {
        a0 a0Var = new a0();
        this.b.b(new l(executor, aVar, a0Var));
        p();
        return a0Var;
    }

    public final <TContinuationResult> g<TContinuationResult> f(Executor executor, a<TResult, g<TContinuationResult>> aVar) {
        a0 a0Var = new a0();
        this.b.b(new n(executor, aVar, a0Var));
        p();
        return a0Var;
    }

    public final Exception g() {
        Exception exception;
        synchronized (this.a) {
            exception = this.f;
        }
        return exception;
    }

    public final TResult h() {
        Object obj;
        synchronized (this.a) {
            f.U(this.c, "Task is not yet complete");
            if (this.d) {
                throw new CancellationException("Task is already canceled.");
            } else if (this.f == null) {
                obj = this.e;
            } else {
                throw new e(this.f);
            }
        }
        return obj;
    }

    public final boolean i() {
        return this.d;
    }

    public final boolean j() {
        boolean z;
        synchronized (this.a) {
            z = this.c;
        }
        return z;
    }

    public final boolean k() {
        boolean z;
        synchronized (this.a) {
            z = this.c && !this.d && this.f == null;
        }
        return z;
    }

    public final <TContinuationResult> g<TContinuationResult> l(Executor executor, f<TResult, TContinuationResult> fVar) {
        a0 a0Var = new a0();
        this.b.b(new v(executor, fVar, a0Var));
        p();
        return a0Var;
    }

    public final void m(Exception exception) {
        f.S(exception, "Exception must not be null");
        synchronized (this.a) {
            f.U(this.c ^ 1, "Task is already complete");
            this.c = true;
            this.f = exception;
        }
        this.b.a(this);
    }

    public final void n(TResult tResult) {
        synchronized (this.a) {
            f.U(this.c ^ 1, "Task is already complete");
            this.c = true;
            this.e = tResult;
        }
        this.b.a(this);
    }

    public final boolean o() {
        synchronized (this.a) {
            if (this.c) {
                return false;
            }
            this.c = true;
            this.d = true;
            this.b.a(this);
            return true;
        }
    }

    public final void p() {
        synchronized (this.a) {
            if (this.c) {
                this.b.a(this);
                return;
            }
        }
    }
}
